import random 
from .get_driver import get_test_module_name_and_id

def random_true(probablity:float):
    if random.random()<probablity:
        return True
    return False


def get_location(ele):
    return (ele.location['x'],ele.location['y'])

def manul_choose():
    print("如果目测通过，请输入 y（或者 Y）: ")
    flag = input()
    if flag in ["y","Y"]:
        print_succeed()
        return True
    else:
        print_failed()
        return False

def print_result_by_func(func,*args,**kw):
    if(callable(func) and func(*args,**kw)):
        print_succeed()
    else:
        print_failed()

def print_result(flag:bool,py_file_abs_path=None):
    test_module,test_id = get_test_module_name_and_id(py_file_abs_path)
    if(flag):
        print_succeed(test_module,test_id)
    else:
        print_failed(test_module,test_id)

def print_succeed(test_module:str=None,test_id:int=None):
    if test_module is not None and test_id is not None:
        print("+++ {}:{}:SUCCEED +++".format(test_module,test_id))
    else:
        print("+++ ::SUCCEED +++")

def print_failed(test_module:str=None,test_id:int=None):
    if test_module is not None and test_id is not None:
        print("--- {}:{}:FAILED ---".format(test_module,test_id))
    else:
        print("--- ::FAILED ---")